/*
 *  Copyright 2012 Iurii Dunko, Iana Potochniak.
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */
package org.opu.yyminijava.codegeneration;

/**
 *
 * @author Iurii Dunko
 * @author Iana Potochniak
 */
public enum ICode {

    // work with data stack
    
    /** 
     * (#n) Push integer value stored in local variable n.
     * Used when we parse math expression and part of it is variables.
     */
    ILOAD, // #n

    /** 
     * (v) Push integer value v. 
     * Used when we parse math expression and part of it is constants (1, 2, ...)
     */
    ICONST, // v

    /** 
     * (#n) Pop value v and store it in local variable n <pre>
     *  int a = ...
     *  ...
     *  b = ...
     *  </pre>
     */
    ISTORE, // #n

    // math operation
    
    /** Pop value v1 , Pop value v2 , Push v2 + v1 */
    IADD,

    /** Pop value v1 , Pop value v2 , Push v2 ∗ v1 */
    IMUL,

    /** Pop value v1 , Pop value v2 , Push v2 / v1 */
    IDIV,

    /** Pop value v1 , Pop value v2 , Push v2 − v1 */
    ISUB,

    /** {@code Pop value v1 , Pop value v2 , Push 1 if v2 < v1 else Push 0 }*/
    ILT,

    /** {@code Pop value v1 , Pop value v2 , Push 1 if v2 > v1 else Push 0 }*/
    IGT,

    /** Pop value v1 , Pop value v2 , Push 0 if v1 ∗ v2 = 0 else Push 1 */
    IAND,
    
    /** Pop value v1 , Pop value v2 , Push 0 if v1 + v2 = 0 else Push 1 */
    IOR,
    
    /** Pop value v1 , Pop value v2 , Push 1 if v1 == v2 else Push 0 */
    IEQUAL,
    
    /** Pop value v1 , Pop value v2 , Push 1 if v1 != v2 else Push 0 */
    INOT_EQUAL,

    /** Pop value v , Push 1 if v = 0 else Push 0 */
    INOT,

    // operators
    
    /** (i) Jump to instruction i */
    GOTO, // i

    /** Pop value v , if v = 0 jump to instruction i, else continue */
    IF_FALSE, // i

    /** Push current activation and switch to the method named m */
    INVOKEVIRTUAL, // m

    /** Pop activation and continue */
    RETURN,

    /** Pop value and print */
    PRINT,

    /** Pop value and print with new line end*/
    PRINTLN,

    /** Execution completed */
    STOP;
}
